include(ExternalProject)

ExternalProject_add(DeprecatedAttribute
    PREFIX "${CMAKE_CURRENT_BINARY_DIR}"
    SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src"
    LOG_CONFIGURE 1
    LOG_BUILD 1
    INSTALL_COMMAND ""
    CMAKE_ARGS
        -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
        -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
)

set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
    ${CMAKE_CURRENT_BINARY_DIR}
)

# 0 - don't check
# 1 - check in stdout
# 2 - check in stderr
set(ENABLE_CHECK_WARNINGS 0)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0.0")
        set(ENABLE_CHECK_WARNINGS 2)
    endif ()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.0.0")
        set(ENABLE_CHECK_WARNINGS 2)
    endif ()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
    if (NOT MSVC_VERSION LESS 1920) # at least MSVC 2019, toolset v142
        set(ENABLE_CHECK_WARNINGS 1)
    endif ()
endif ()
set(DEPRECATED_ATTRIBUTE_COMPILE_DEFINITIONS
    "DEPRECATED_ATTRIBUTE_TEST_CHECK_WARNINGS=${ENABLE_CHECK_WARNINGS}" PARENT_SCOPE)
